import request from '@/utils/request';

export async function getFileInfoByPage(params: any) {
  return request('/api/project/getFileInfoByPage', {
    method: 'POST',
    data: params,
  });
}

export async function uploadFileInfo(para: any) {
  return request('/api/project/uploadFileInfo', {
    method: 'POST',
    requestType: 'form',
    data: para.file,
    headers: {
      'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryX72QZDdfwlF5U73J',
    },
    params: {
      infoId: para.infoId,
      category: para.category,
      fileName: '',
      memo: para.memo,
    },
  });
}

//附件编辑
export async function getFileInfoByPageAndInfoId(params: any) {
  return request('/api/project/getFileInfoByPageAndInfoId', {
    method: 'POST',
    data: params,
  });
}

export async function getFileType(params: any) {
  return request('/api/project/getFileType', {
    method: 'POST',
  });
}

export async function getProjectName(params: any) {
  return request('/api/project/getProjectInfoSimp', {
    method: 'POST',
  });
}

export async function updateFileInfo(params: any) {
  console.log(params, 'params');
  return request('/api/project/updateFileInfo2', {
    method: 'POST',
    requestType: 'form',
    params: {
      infoId: params.infoId,
      id: params.id,
      category: params.category,
    },
    data: params.file,
  });
}

export async function delFileInfo(params: any) {
  return request('/api/project/delFileInfo', {
    method: 'POST',
    data: params,
  });
}

export async function exportFileInfo(params: any) {
  return request('/api/project/exportFileInfo', {
    method: 'POST',
    data: params,
    responseType: 'blob',
  });
}

//下载文件
export async function downloadFile(para: any) {
  return request('/api/project/downloadFile', {
    method: 'GET',
    responseType: 'blob',
    params: {
      id: para,
    },
  });
}
export default {
  getFileInfoByPage,
  downloadFile,
  uploadFileInfo,
  updateFileInfo,
  delFileInfo,
  exportFileInfo,
};
